package com.yangrong.thread.chapter8;

public class ProduceConsumerVersion1 {

	private int i = 1;

	private final Object LOCK = new Object();

	private void produce() {
		synchronized (LOCK) {
			System.out.println("P->" + (i++));
		}
	}
	
	private void consume() {
		synchronized (LOCK) {
			System.out.println("P->" + i);
		}
	}
	
	public static void main(String[] args) {
		ProduceConsumerVersion1 pc = new ProduceConsumerVersion1();
		
		new Thread("P") {
			public void run() {
				pc.produce();
			};
		}.start();
		
		new Thread("C") {
			public void run() {
				pc.consume();
			};
		}.start();
	}

}
